package com.easy.cms.base.exception;

import com.easy.cms.base.CommonResult;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public CommonResult<?> handleException(HttpServletRequest request, Exception e) {
        // 假设这里修改为正确的调用方式，具体根据实际情况调整
        return CommonResult.<String>failed(e.getMessage());
    }

    @ExceptionHandler(CustomException.class)
    @ResponseBody
    public CommonResult<?> handleCustomException(CustomException e) {
        return CommonResult.<String>failed(e.code,e.getMessage());
    }
}